package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class TravelCommend extends BaseDomain{
    public static final int TYPE_WEEK = 1;//每周
    public static final int TYPE_MONTH = 2;//每月
    public static final int TYPE_TOURS = 3;//攻略
    //关联游记
    private Travel travel;
    private Travelcontent travelcontent;
    //推荐标题
    private String title;
    //副标题
    private String subTitle;
    //封面
    private String coverUrl;
    //推荐日期
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date schedule;
    //推荐类型
    private Integer type;
    //类型名字
    public String getTypeName(){
        String msg = "每周推荐";
        if(TYPE_MONTH==type){
            msg = "每月推荐";
        }else if(TYPE_TOURS==type){
            msg = "攻略推荐";
        }
        return msg;
    }
    //获取json属性
    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("subTitle",subTitle);
        map.put("coverUrl",coverUrl);
        map.put("travelId",travel.id);
        SimpleDateFormat smd = new SimpleDateFormat("yyyy-MM-dd");
        String format = smd.format(schedule);
        map.put("schedule",format);
        map.put("type",type);
        map.put("typeName",getTypeName());
        return JSONUtil.toJSONString(map);
    }
}